package com.bawei.module_service.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_service.R
import com.bawei.module_service.databinding.MaintainitemBinding
import com.bawei.module_service.model.MaintainModelItem



class MaintainAdapter :RecyclerView.Adapter<MaintainAdapter.MaintainViewHolder>(){
    //
    var maintainList= mutableListOf<MaintainModelItem>()


    fun setData(data:List<MaintainModelItem>){
        maintainList.clear()
        maintainList.addAll(data)
        notifyDataSetChanged()
    }


    class MaintainViewHolder(val binding: MaintainitemBinding):RecyclerView.ViewHolder(binding.root)

    //g88888
    @SuppressLint("SuspiciousIndentation")
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MaintainViewHolder {
      val binding=MaintainitemBinding.inflate(
          LayoutInflater.from(parent.context),
          parent,
          false
      )
        return MaintainViewHolder(binding)
    }

    override fun getItemCount(): Int {
      return maintainList.size
    }

    @SuppressLint("SuspiciousIndentation")
    override fun onBindViewHolder(holder: MaintainViewHolder, position: Int) {
      val binding=DataBindingUtil.getBinding<MaintainitemBinding>(holder.itemView)
        binding?.repairTime?.setText("保修时间："+maintainList[position].repairTime)
        binding?.repairName?.setText("报修人:"+maintainList[position].repairName)
        binding?.repairLocation?.setText("位置："+maintainList[position].repairLocation)
        binding?.faultDescription?.setText(maintainList[position].faultDescription)
        binding?.orderNumber?.setText("工单号："+maintainList[position].orderNumber)


    if (maintainList[position].processingStatus=="处理中"){
        binding?.processingStatus?.setTextColor(Color.parseColor("#2B8FE7"))
        binding?.processingStatus?.setText("处理中")
        binding?.processingStatus?.background= ContextCompat.getDrawable(holder.itemView.context,R.drawable.service_rounded_corners3)

        }else if (maintainList[position].processingStatus=="已完成"){

            binding?.processingStatus?.setTextColor(Color.parseColor("#4F9E52"))
            binding?.processingStatus?.setText("已完成")
            binding?.processingStatus?.background= ContextCompat.getDrawable(holder.itemView.context,R.drawable.service_rounded_corners1)

        }else{

        binding?.processingStatus?.setTextColor(Color.parseColor("#F68A1A"))
        binding?.processingStatus?.setText("待处理")
        binding?.processingStatus?.background= ContextCompat.getDrawable(holder.itemView.context,R.drawable.service_rounded_corners2)

    }
        }



    }
